﻿Function Remove-MemoryToVm([string]$VCenter,[string]$VCUsername,[string]$VCPassword,[string]$VMName,[int]$Memory,[int]$ttw=180){

    Add-PSSnapin VMware.VimAutomation.Core

    Connect-VIServer -Server $VCenter -User $VCUsername -Password $VCPassword

    Get-VM -Name $VMName | Shutdown-VMGuest -Confirm:$false
    Start-Sleep -Seconds $ttw
    Get-VM -Name $VMName | Set-VM -MemoryGB $Memory -Confirm:$false
    Start-VM -VM $VMName -Confirm:$false
    
    Disconnect-VIServer -Server $VCenter -Confirm:$fasle
    Remove-PSSnapin VMware.VimAutomation.Core
}